package org.budo.redis.jdbc.driver.statement.key;

import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.budo.redis.jdbc.driver.BudoRedisJdbcConnection;
import org.budo.redis.jdbc.driver.BudoRedisJdbcPreparedStatement;
import org.budo.redis.jdbc.driver.executor.RedisStatementExecutor;
import org.budo.redis.jdbc.driver.statement.AbstractRedisStatement;

/**
 * @author lmw
 */
public class PEXPIREAT extends AbstractRedisStatement {
    @Override
    public void execute(PreparedStatement preparedStatement) throws SQLException {
        byte[] key = this.parameter(0, preparedStatement);
        Long milliSecondsTimestamp = this.parameterNumber(1, preparedStatement).longValue();

        RedisStatementExecutor statementExecutor = ((BudoRedisJdbcConnection) preparedStatement.getConnection()).getStatementExecutor();
        Long pexpireAt = statementExecutor.pexpireAt(key, milliSecondsTimestamp);

        ((BudoRedisJdbcPreparedStatement) preparedStatement).setUpdateCount(pexpireAt.intValue());
    }
}